package com.xstablet.activity;

import android.content.pm.ActivityInfo;
import android.os.Handler;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.lib.app.ARouterPathUtils;
import com.lib.fastkit.db.shared_prefrences.SharedPreferenceManager;
import com.lib.fastkit.utils.log.LogUtil;
import com.lib.fastkit.utils.share.tool.StringUtil;
import com.lib.fastkit.utils.status_bar.StatusBarUtil;
import com.lib.ui.activity.BaseAppActivity;
import com.xstablet.R;

@Route(path = ARouterPathUtils.Tablet_App_LaunchActivity)
public class LaunchActivity extends BaseAppActivity {

    @Override
    protected void onCreateView() {
        StatusBarUtil.statusBarTintColor(this, getResources().getColor(R.color.white));

    }

    @Override
    protected void onResume() {
        super.onResume();

        /**
         * 设置为横屏
         */
        if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

        isGoGuide();
    }

    private void isGoGuide() {

        boolean flag = SharedPreferenceManager.getInstance(this).getUserCache().getShow();
        String token = SharedPreferenceManager.getInstance(this).getUserCache().getUserToken();

        LogUtil.e(flag + "");

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {

                if (!flag) {

                    LogUtil.e("进入引导页");
                    ARouter.getInstance().build(ARouterPathUtils.Tablet_App_GuideActivity).navigation();
                } else {

                    if (StringUtil.isNotEmpty(token, true)) {

                        LogUtil.e("进入主页");
                        ARouter.getInstance().build(ARouterPathUtils.Tablet_App_MainActivity).navigation();
                    } else {

                        LogUtil.e("进入登录页");
                        ARouter.getInstance().build(ARouterPathUtils.Tablet_User_LoginActivity).navigation();
                    }
                }
            }
        }, 1500);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_launch;
    }

}
